﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharepointLogReader
{
    public class Settings
    {
        #region Settings functions
        private static Settings _Settings;
        public static Settings Current
        {
            get
            {
                if (_Settings == null)
                {
                    try
                    {
                        _Settings = (Settings)Serializer.ReadObject(Consts.SETTINGS_FILE, typeof(Settings));
                    }
                    catch (Exception)
                    {
                        _Settings = new Settings();
                        Save(_Settings, resetCache: false);
                    }
                }
                return _Settings;
            }
        }
        public static void Save(Settings settings, bool resetCache = true)
        {
            Serializer.SaveObject(settings, Consts.SETTINGS_FILE);
            if (resetCache) _Settings = null;
        }
        #endregion

        #region Properties
        public string LogDir 
        {
            get
            {
                return _LogDir;
            }
            set
            {
                _LogDir = value;
            }
        }
        private string _LogDir = Consts.ROOT_LOG_FOLDER_DEFAULT;
        public int MaxLogFiles
        {
            get
            {
                return _MaxLogFiles;
            }
            set
            {
                _MaxLogFiles = value;
            }
        }
        private int _MaxLogFiles = Consts.MAX_LOG_FILES_DEFAULT;
        public int MaxSearchLines
        {
            get
            {
                return _MaxSearchLines;
            }
            set
            {
                _MaxSearchLines = value;
            }
        }
        private int _MaxSearchLines = Consts.MAX_SEARCH_LINES_DEFAULT;
        #endregion

    }
}
